﻿// (c) Copyright 2012 by Michael P. Ferrell
// MikeFerrell@acm.org
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MPFerrell.Ftf
{
    public partial class FtfMainForm : Form
    {
        public FtfMainForm()
        {
            InitializeComponent();
        }

        private void FtfMainForm_Load(object sender, EventArgs e)
        {

        }

        public void FillCurrentTemplateWithClipboard()
        {
            Console.WriteLine("FillCurrentTemplateWithClipboard: entered");
            //if (lstTemplates.SelectedIndex > -1)
            {
                Console.WriteLine("FillCurrentTemplateWithClipboard: inside if");
                try
                {
                    string strClipboard = Clipboard.GetText();

                    string strResult = CurrentFilledTextForGivenClipValue(strClipboard);

                    Console.WriteLine("FillCurrentTemplateWithClipboard: replaced lower clipboard token");
                    Clipboard.SetText(strResult);
                    Console.WriteLine("FillCurrentTemplateWithClipboard: copied result to clipboard");
                }
                catch (Exception objException)
                {
                    Console.WriteLine(objException.Message);
                }
            }
            Console.WriteLine("FillCurrentTemplateWithClipboard: leaving");
        }

        public void SelectTemplateInGui(int TemplateIndexIn)
        {
            lstTemplates.SelectedIndex = TemplateIndexIn;
        }

        public string CurrentFilledTextForGivenClipValue(string strClipTextIn) //strClipTextIn)
        {
            string strCurTemplate = lstTemplates.Items[lstTemplates.SelectedIndex].ToString();
            Console.WriteLine("FillCurrentTemplateWithClipboard: got template");
            Console.WriteLine("FillCurrentTemplateWithClipboard: got clipboard text");
            string strResult = strCurTemplate.Replace("%[Clipboard]", strClipTextIn);
            Console.WriteLine("FillCurrentTemplateWithClipboard: replaced proper clipboard token");
            strResult = strResult.Replace("%[clipboard]", strClipTextIn);
            return strResult;
        }

        private void lstTemplates_DoubleClick(object sender, EventArgs e)
        {
            FillCurrentTemplateWithClipboard();
        }

 
    }
}
